/**
  ******************************************************************************
  * @file    SPEED_CFG.h
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   Outputs Driver
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef  __SPEED_CFG_H__
#define  __SPEED_CFG_H__


#ifdef __cplusplus
 extern "C" {
#endif


/**
  * @brief  INCLUDE FILES.
  */


/**
  * @brief GLOBALS RAM definition
  */
#ifdef   SPEED_CFG_GLOBALS
#define  SPEED_CFG_EXT
#else
#define  SPEED_CFG_EXT  extern
#endif

/* Timer base setting */                                               
#define TIM3CountCLK_FREQ                      ((uint32_t) 7200000)   /* HZ */



                        /***********************************************************/
                        /******************ENG_SPEED Input define  *****************/
                        /***********************************************************/

#define ENGSPEED_TIMRCCPeriph                  RCC_APB1Periph_TIM3
                                               
#define ENGSPEED_TIMPrescaler                  (uint16_t)(SYSTIM2T7CLK_FREQ/TIM3CountCLK_FREQ-1)
#define ENGSPEED_TIMCounterMode                TIM_CounterMode_Up
#define ENGSPEED_TIMPeriod                     65535
#define ENGSPEED_TIMClockDivision              TIM_CKD_DIV1
#define ENGSPEED_TIMRepetitionCounter          0
#define ENGSPEED_TIM                           TIM3
                                               
#define ENGSPEED_ITx                           (TIM_IT_CC1   | TIM_IT_CC2   | TIM_IT_Update  )
#define ENGSPEED_FLAGx                         (TIM_FLAG_CC1 | TIM_FLAG_CC2 | TIM_FLAG_Update)
#define ENGSPEED_IRQChannel                    TIM3_IRQn
#define ENGSPEED_IRQPrePrio                    0x0D
#define ENGSPEED_IRQSubPrio                    0x0D
                                               
                                               
#define ENGSPEED_TIMOCMode                     TIM_OCMode_Timing     
#define ENGSPEED_TIMOutputState                TIM_OutputState_Disable
#define ENGSPEED_TIMOutputNState               TIM_OutputNState_Disable
#define ENGSPEED_TIMOCPulse                    60000
#define ENGSPEED_TIMOCPolarity                 TIM_OCPolarity_Low 
#define ENGSPEED_TIMOCNPolarity                TIM_OCNPolarity_Low 
#define ENGSPEED_TIMOCIdleState                TIM_OCIdleState_Reset 
#define ENGSPEED_TIMOCNIdleState               TIM_OCNIdleState_Reset 


/**
  * @brief   Signal Catpure in Timer
  * @param3  ENG_SPEED------------PC6  (TIM3-CH1)
  */
#define ENGSPEED_GPIO_PinRemap                 GPIO_FullRemap_TIM3
#define ENGSPEED_RCCGPIOPeriph                 RCC_APB2Periph_GPIOC
                                               
#define ENGSPEED_GPIOxBitx                     GPIO_Pin_6
#define ENGSPEED_GPIOSpeed                     GPIO_Speed_2MHz
#define ENGSPEED_GPIOModeI                     GPIO_Mode_IN_FLOATING
#define ENGSPEED_GPIOxPort                     GPIOC
                                               
#define ENGSPEED_TIMChannel                    TIM_Channel_1
#define ENGSPEED_TIM_ICPolarity                TIM_ICPolarity_Rising
#define ENGSPEED_TIM_ICSelection               TIM_ICSelection_DirectTI
#define ENGSPEED_TIM_ICPrescaler               TIM_ICPSC_DIV1
#define ENGSPEED_TIM_ICFilter                  0x0
#define ENGSPEED_TIMx                          TIM3


/* Crank Pcfg */
#define EnginePcfgBFOrd_CrankDisFreqOpt                             (Adr_CrankDisFreqOpt      -Adr_CrankDisFreqOpt)
#define EnginePcfgBFOrd_CrankDisSpeedOpt                            (Adr_CrankDisSpeedOpt     -Adr_CrankDisFreqOpt)
#define EnginePcfgBFOrd_CrankDisOilOpt                              (Adr_CrankDisOilPressOpt  -Adr_CrankDisFreqOpt)
#define EnginePcfgBFOrd_CrankDisFreqVal                             (Adr_CrankDisFreqVal      -Adr_CrankDisFreqOpt)
#define EnginePcfgBFOrd_CrankDisSpeedVal                            (Adr_CrankDisSpeedVal     -Adr_CrankDisFreqOpt)
#define EnginePcfgBFOrd_CrankDisOilVal                              (Adr_CrankDisOilPressVal  -Adr_CrankDisFreqOpt)
#define EnginePcfgBFTOT_CrankNum                                    (EnginePcfgBFOrd_CrankDisOilVal+1)

#define EnginePcfgBFOrd_CrankDisDPlusOpt                            (Adr_CrankDisDPlusOpt     -Adr_CrankDisDPlusOpt)
#define EnginePcfgBFOrd_CrankDisDPlusVal                            (Adr_CrankDisDPlusVal     -Adr_CrankDisDPlusOpt)
#define EnginePcfgBFTOT_CrankDPlusNum                               (EnginePcfgBFOrd_CrankDisDPlusVal+1)

/* Pcfg Buffer Order */

#define SpeedPcfgBFOrd_SpeedOnLoad                                  (Adr_EngineSpeedOnLoad             -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedShutdownOpt                         (Adr_EngineOverSpeedShutdownOpt    -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedShutdownTrip                        (Adr_EngineOverSpeedShutdownTrip   -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedShutdownDelay                       (Adr_EngineOverSpeedShutdownDelay  -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedPreAlarmOpt                         (Adr_EngineOverSpeedPreAlarmOpt    -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedPreAlarmTrip                        (Adr_EngineOverSpeedPreAlarmTrip   -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedPreAlarmReturn                      (Adr_EngineOverSpeedPreAlarmReturn -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedPreAlarmDelay                       (Adr_EngineOverSpeedPreAlarmDelay  -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedPreAlarmOpt                        (Adr_EngineUnderSpeedPreAlarmOpt   -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedPreAlarmTrip                       (Adr_EngineUnderSpeedPreAlarmTrip  -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedPreAlarmReturn                     (Adr_EngineUnderSpeedPreAlarmReturn-Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedPreAlarmDelay                      (Adr_EngineUnderSpeedPreAlarmDelay -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedShutdownOpt                        (Adr_EngineUnderSpeedShutdownOpt   -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedShutdownTrip                       (Adr_EngineUnderSpeedShutdownTrip  -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_UnderSpeedShutdownDelay                      (Adr_EngineUnderSpeedShutdownDelay -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_LossOfSpeedAction                            (Adr_EngineLossOfSpeedAction       -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_LossOfSpeedDelay                             (Adr_EngineLossOfSpeedDelay        -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_OverSpeedOvershoot                           (Adr_EngineOverSpeedOvershoot      -Adr_EngineSpeedOnLoad)
#define SpeedPcfgBFOrd_RatedSpeed                                   (SpeedPcfgBFOrd_OverSpeedOvershoot+1)
#define SpeedPcfgBFTOT_AlarmNum                                     (SpeedPcfgBFOrd_RatedSpeed        +1)
                                                                    
                                                                    
/* Raw Alarm Buffer Order */                                        
#define SpeedRawAlarmOrd_SpeedLoss                                  (RawAlarm_SpeedLoss    -RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedOverShut                              (RawAlarm_SpeedOverShut-RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedOverWarn                              (RawAlarm_SpeedOverWarn-RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedHighShut                              (RawAlarm_SpeedHighShut-RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedHighWarn                              (RawAlarm_SpeedHighWarn-RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedLowWarn                               (RawAlarm_SpeedLowWarn -RawAlarm_SpeedLoss)
#define SpeedRawAlarmOrd_SpeedLowShut                               (RawAlarm_SpeedLowShut -RawAlarm_SpeedLoss)
#define SpeedRawAlarmTOT_Num                                        (SpeedRawAlarmOrd_SpeedLowShut+1)




#ifdef __cplusplus
}
#endif


#endif   /*  __SPEED_CFG_H__  */

/******************* (C) COPYRIGHT 2010 Feirui *****END OF FILE****/